package com.weasel.weixin.commons.message.bean;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.weasel.helper.DocumentConverter;

import java.io.InputStream;

/**微信事件推送消息体
 * Created by Dylan on 2015/10/15.
 */
@XStreamAlias("xml")
public class WeixinPostEventXmlMessage {

    @XStreamAlias("ToUserName")
    private String toUserName; //开发者微信号

    @XStreamAlias("FromUserName")
    private String fromUserName; //发送方帐号（一个OpenID）

    @XStreamAlias("CreateTime")
    private long createTime; //消息创建时间 （整型）

    @XStreamAlias("MsgType")
    private String msgType; //消息类型，event

    @XStreamAlias("Event")
    private String event; //事件类型，subscribe(订阅)、unsubscribe(取消订阅)

    @XStreamAlias("EventKey")
    private String eventKey;//事件KEY值，qrscene_为前缀，后面为二维码的参数值

    @XStreamAlias("Ticket")
    private String ticket; //二维码的ticket，可用来换取二维码图片

    @XStreamAlias("Latitude")
    private  double latitude;//地理位置纬度

    @XStreamAlias("Longitude")
    private double longitude; //地理位置经度

    @XStreamAlias("Precision")
    private double precision;  //地理位置精度


    public String getToUserName() {
        return toUserName;
    }

    public void setToUserName(String toUserName) {
        this.toUserName = toUserName;
    }

    public String getFromUserName() {
        return fromUserName;
    }

    public void setFromUserName(String fromUserName) {
        this.fromUserName = fromUserName;
    }

    public long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(long createTime) {
        this.createTime = createTime;
    }

    public String getMsgType() {
        return msgType;
    }

    public void setMsgType(String msgType) {
        this.msgType = msgType;
    }

    public String getEvent() {
        return event;
    }

    public void setEvent(String event) {
        this.event = event;
    }

    public String getEventKey() {
        return eventKey;
    }

    public void setEventKey(String eventKey) {
        this.eventKey = eventKey;
    }

    public String getTicket() {
        return ticket;
    }

    public void setTicket(String ticket) {
        this.ticket = ticket;
    }

    public double getLatitude() {
        return latitude;
    }

    public void setLatitude(double latitude) {
        this.latitude = latitude;
    }

    public double getLongitude() {
        return longitude;
    }

    public void setLongitude(double longitude) {
        this.longitude = longitude;
    }

    public double getPrecision() {
        return precision;
    }

    public void setPrecision(double precision) {
        this.precision = precision;
    }

    /**
     * 未加密的消息
     * @param inputStream
     * @return
     */
    public static WeixinPostEventXmlMessage fromWeixinPostInputSteam(InputStream inputStream){

        return DocumentConverter.xmlToEntity(inputStream, WeixinPostEventXmlMessage.class);
    }


}
